﻿

//----------------------------------------------------------------------
// <copyright file="ServiceBook.cs" company="O-RID">
// Copyright (c)2010 O-RID Co.,Ltd.
// </copyright>
// <author>lidawei</author>
// <summary> 
// 作成日： 2010/10/18
// </summary>
//----------------------------------------------------------------------




namespace Orid.Management.SOHO.Book.ServiceLibrary
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using  Data;
using Orid.Management.SOHO.Book.ServiceLibrary.Logic;

    // 注意: 如果更改此处的类名 "ServiceBook"，也必须更新 App.config 中对 "ServiceBook" 的引用。
    public class ServiceBook : IServiceBook
    { 
        public DateTime   GetCurrentTime()
        {
            onMessage("GetCurrentTime method:");

            return System.DateTime.Now;
        }

        public bool AddSchedule(string operatorID, int accountID, DateTime dateFrom, DateTime dateTo)
        {

            onMessage(string.Format("AddSchedule method:OPID:{0},AccountID:{1},BookFrom:{2},BookTo{2} ", operatorID,accountID, dateFrom.ToString("1980-12-31 12:12:12"), dateTo.ToString("1980-12-31 12:12:12")));


            bool boolResult;

            try
            {
                boolResult = DataBase.AddSchedule(operatorID, accountID, dateFrom, dateTo);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                throw;
            }

            return boolResult;

        }

        public bool RemoveSchedule(string operatorID, DateTime dateFrom, DateTime dateTo)
        {
            onMessage(string.Format("RemoveSchedule method:OPID:{0},BookFrom:{1},BookTo{2} ", operatorID, dateFrom.ToString("1980-12-31 12:12:12"), dateTo.ToString("1980-12-31 12:12:12")));

            bool boolResult;

            try
            {
                boolResult = DataBase.RemoveSchedule(operatorID,  dateFrom, dateTo);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                throw;
            }

            return boolResult;
        }

        /// <summary>
        /// Info
        /// 记录程序操作信息
        /// </summary>
        /// <param name="message">message 程序操作信息</param>
        public void Info(string message)
        {

            onMessage(string.Format("Info method:{0}", message));

            Log.Info(message);
        }

        /// <summary>
        /// Error
        /// 记录程序错误信息
        /// </summary>
        /// <param name="message">message 程序错误信息</param>
        public void Error(string message)
        {
            onMessage(string.Format("Error method:{0}", message));

            Log.Error(message);
        }

        private  void onMessage(string msg)
        {
              Log.Info(msg);
              onAcitonEvent(new ActionEventArgs { Msg =msg });
        }

        public static event EventHandler AcitonEvent;

        public static void onAcitonEvent(ActionEventArgs e)
        {

            if (AcitonEvent != null)
            {
                AcitonEvent(null, e);
            }

        }
        
        public class ActionEventArgs : EventArgs
        {
            public string Msg { get; set; }
        }

    }

}
